<template lang="html">
  <div class="home">

    <!-- <div class='clearfix'>
      <el-button type="danger" class='pull-right mb10' icon="el-icon-delete" style='margin-right:10px;' @click="tourl('/content/trash')">回收箱</el-button>
    </div> -->

    <div class='searchView'>
      <el-form :inline="true" class="demo-form-inline">
        
        <el-form-item label="">
          <el-input placeholder='输入用户名称…' @keydown.enter='getList(1)' v-model='searchName'></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click='getList(1)'>查询</el-button>
        </el-form-item>

      </el-form>
    </div>

    <div class='tableView'>
      <el-tag type="info" class='mb10'>共{{totalData}}条记录</el-tag>
      <el-table
        ref="multipleTable"
        :data="tableData"
        v-loading='loading'
        align='center'
        border
        height='500'
        tooltip-effect="dark">

        <el-table-column
        align='center'
        label="角色">
          <template slot-scope="scope">
            {{scope.row.certifiedAuthor?'书籍作者':'普通用户'}}
          </template>
        </el-table-column>

        <el-table-column
        align='center'
        prop='penName'
        label="用户名">
        </el-table-column>

        <el-table-column
        align='center'
        label="用户头像">
          <template slot-scope="scope">
            <img :src="scope.row.avatar" class='cover'>
          </template>
        </el-table-column>

        <el-table-column
        align='center'
        prop='personalitySignature'
        label="签名">
        </el-table-column>

        <el-table-column
        align='center'
        prop='createTime'
        label="创建时间">
        </el-table-column>

        <el-table-column
        label=""
        width='220'
        align='center'>
          <template slot-scope="scope">
            <!-- <el-button size='mini' type="primary">首推</el-button> -->
            <el-button size='mini' type="danger" v-show='scope.row.openStatus == 0' @click='delIt(scope.row.id,1)'>封号</el-button>
            <el-button size='mini' type="success" v-show='scope.row.openStatus == 1' @click='delIt(scope.row.id,0)'>解封</el-button>

          </template>
        </el-table-column>

      </el-table>

      <div class="pageBlock">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageSize"
          layout="prev, pager, next, jumper, sizes"
          :total="totalData">
        </el-pagination>
      </div>
    </div>

  </div>
</template>
<script>
export default {

  data () {
    return {
      tableData:[1],
      loading:false,
      status:'UN_PUBLISHED',
      date:'',
      searchName:'',
      options: [
        {
          value: '',
          label: '全部'
        },
        {
          value:'UN_PUBLISHED',
          label:'全站用户'
        },
        {
          value:'PUBLISHED',
          label:'书籍作者'
        },
        {
          value:'AUDITING',
          label:'普通用户'
        }
      ],
      totalData:0,
      pageSize:10,
      searchUserId:null,
      currentPage:1
    }
  },
  methods:{
    delIt(userId,flag){
      this.$confirm('是否确认操作？',{center:true})
      .then(res =>{

        this.loading = true;
        tools.ajax({
            url:`/v1/user/${userId}/enable/${flag}`,
            type:'POST'
        })
        .then(res => {
          this.loading = false;
          if(res.code == 200){
            tools.toastOk('操作成功');
            this.getList(1);
          }
        })
        .catch(e => {
          this.loading = false;
        })

      }).catch( e=> {})
    },
    create(){
      if(!this.searchUserId){
        tools.toastWarn('请选择用户');
        return
      };

      this.tourl('/content/user/create',{userId:this.searchUserId});
    },
    tourl(url,query){
      tools.router.push({path:url,query:query || {}})
    },
    getList(page){
      if(page){
        this.currentPage = page;
      }

      this.loading = true;
      tools.ajax({
        url:'/v1/user/list',
        data:{
          page:this.currentPage,
          pageSize:this.pageSize,
          name:this.searchName
        },
        type:'POST'
      })
      .then(res => {
        this.loading = false;
        if(res.code == 200){
          this.tableData = res.data.rows;
          this.totalData = +res.data.total;
        }
      })
      .catch(e => {
        this.loading = false;
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.getList();
    }
  },
  mounted(){
    var _this = this;
    this.getList();
  },
  components:{
  }
}
</script>

<style scoped lang='scss'>
  @import '../../assets/scss/tool.scss';
  .home{
    
  }
  .cover{
    width: 100px;
    height: 100px;
  }
</style>